﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Reflection;
using System.Diagnostics;

using System.IO;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.ComponentModel;

namespace TableModule
{
    [XmlInclude(typeof(TableSingleData))]
    public class TableSingleData
    {
        public string strTableName;
        public BindingList<TableDataLocal> listTableDataLocal;
        [XmlIgnore]
        public Dictionary<string, TableDataLocal> dicTableDataLocal;

        public BindingList<TableDataPosition> listTableDataPos { get; set; }
        [XmlIgnore]
        public Dictionary<string, TableDataPosition> dicTableDataPos;

        public BindingList<TableDataSpeed> listTableDataSpeed;
        [XmlIgnore]
        public Dictionary<string, TableDataSpeed> dicTableDataSpeed;

        public BindingList<TableDataTool> listTableDataTool;
        [XmlIgnore]
        public Dictionary<string, TableDataTool> dicTableDataTool;
        public TableSingleData()
        {
            listTableDataLocal = new BindingList<TableDataLocal>();
            dicTableDataLocal = new Dictionary<string, TableDataLocal>();
            listTableDataPos = new BindingList<TableDataPosition>();
            dicTableDataPos = new Dictionary<string, TableDataPosition>();
            listTableDataSpeed = new BindingList<TableDataSpeed>();
            dicTableDataSpeed = new Dictionary<string, TableDataSpeed>();
            listTableDataTool = new BindingList<TableDataTool>();
            dicTableDataTool = new Dictionary<string, TableDataTool>();

        }
        public void AddNewPos(TableDataPosition newPos)
        {
            listTableDataPos.Add(newPos);
            dicTableDataPos = listTableDataPos.ToDictionary(p => p.strName);
        }
        public void RemovePos(int index)
        {
            listTableDataPos.RemoveAt(index);
            dicTableDataPos = listTableDataPos.ToDictionary(p => p.strName);
        }
        public void ModifyPos(int index, TableDataPosition newPos)
        {
            if (dicTableDataPos.ContainsKey(newPos.strName))
            {
              
            }
            else
            {
                listTableDataPos[index].strName = newPos.strName;               
            }
            dicTableDataPos = listTableDataPos.ToDictionary(p => p.strName);
        }
        public void AddNewSpd(TableDataSpeed newSpd)
        {
            listTableDataSpeed.Add(newSpd);
            dicTableDataSpeed = listTableDataSpeed.ToDictionary(p => p.strName);
        }
        public void RemoveSpd(int index)
        {
            listTableDataSpeed.RemoveAt(index);
            dicTableDataSpeed = listTableDataSpeed.ToDictionary(p => p.strName);
        }
        public void ModifySpd(int index, TableDataSpeed newSpd)
        {
            if (dicTableDataSpeed.ContainsKey(newSpd.strName))
            {

            }
            else
            {
                listTableDataSpeed[index].strName = newSpd.strName;
            }
            dicTableDataSpeed = listTableDataSpeed.ToDictionary(p => p.strName);
        }
        public void AddNewLocal(TableDataLocal newLocal)
        {
            listTableDataLocal.Add(newLocal);
            dicTableDataLocal = listTableDataLocal.ToDictionary(p => p.strName);
        }
        public void RemoveLocal(int index)
        {
            listTableDataLocal.RemoveAt(index);
            dicTableDataLocal = listTableDataLocal.ToDictionary(p => p.strName);
        }
        public void ModifyLocal(int index, TableDataLocal newLocal)
        {
            if (dicTableDataLocal.ContainsKey(newLocal.strName))
            {

            }
            else
            {
                listTableDataLocal[index].strName = newLocal.strName;
            }
            dicTableDataLocal = listTableDataLocal.ToDictionary(p => p.strName);
        }
        public void AddNewTool(TableDataTool newTool)
        {
            listTableDataTool.Add(newTool);
            dicTableDataTool = listTableDataTool.ToDictionary(p => p.strName);
        }
        public void RemoveTool(int index)
        {
            listTableDataTool.RemoveAt(index);
            dicTableDataTool = listTableDataTool.ToDictionary(p => p.strName);
        }
        public void ModifyTool(int index, TableDataTool newTool)
        {
            if (dicTableDataTool.ContainsKey(newTool.strName))
            {

            }
            else
            {
                listTableDataTool[index].strName = newTool.strName;
            }
            dicTableDataTool = listTableDataTool.ToDictionary(p => p.strName);
        }
        public void InsertPos(int index, TableDataPosition newPos)
        {
            listTableDataPos.Insert(index,newPos);
            dicTableDataPos = listTableDataPos.ToDictionary(p => p.strName);
        }
        public void InsertSpd(int index, TableDataSpeed newSpeed)
        {
            listTableDataSpeed.Insert(index, newSpeed);
            dicTableDataSpeed = listTableDataSpeed.ToDictionary(p => p.strName);
        }
        public void InsertLocal(int index, TableDataLocal newLocal)
        {
            listTableDataLocal.Insert(index, newLocal);
            dicTableDataLocal = listTableDataLocal.ToDictionary(p => p.strName);
        }
        public void InsertTool(int index, TableDataTool newTool)
        {
            listTableDataTool.Insert(index, newTool);
            dicTableDataTool = listTableDataTool.ToDictionary(p => p.strName);
        }
    }
}
